---
import { Image } from './Image';
import { getPageNameFromPath } from '@features/docs/utils/urlPaths';
import { getPageImages } from '@features/docs/utils/filesData';

interface Props {
    pageName?: string;
    imagePath: string;
    alt: string;
    width?: string;
    height?: string;
    minWidth?: string;
    maxWidth?: string;
}

const { pageName: propPageName, imagePath, alt, ...props } = Astro.props as Props;

const pageName = propPageName ? propPageName : getPageNameFromPath(Astro.url.pathname);

const { imageSrc } = await getPageImages({
    pageName,
    imagePath,
});
---

{imageSrc && <Image client:load alt={alt} src={imageSrc} {...props} />}
